import axios from "../utils/axios";
import { BASE_URL } from "../config/config";
// 获取文章列表
export const getArticleList = () => {
  return axios.get("/articles/getArticleList");
};

// 添加文章
export const addArticle = (articleData) => {
  return axios.post("/articles/addArticle", articleData);
};

// 删除文章
export const deleteArticle = (id) => {
  return axios.delete(`/articles/deleteArticle/${id}`);
};

// 更新文章
export const updateArticle = (id, articleData) => {
  return axios.put(`/articles/updateArticle/${id}`, articleData);
};

// 查看文章内容

export const getArticleContent = (id) => {
  return axios.get(`/articles/getArticleContent/${id}`);
};

export const uploadImage = async (file) => {
  const formData = new FormData();
  formData.append("image", file);
  try {
    const response = await axios.post(
      `${BASE_URL}/articles/uploadImage`,
      formData,
      {
        headers: {
          "Content-Type": "multipart/form-data",
          Authorization: `${localStorage.getItem("token")}`,
        },
      }
    );
    return response;
  } catch (error) {
    console.error("Error uploading image:", error);
    throw error;
  }
};
